// li_han/service/CommentService.java
package com.example.li_han.service;


import com.example.li_han.dao.PingLunDao;
import com.example.li_han.pojo.PingLun;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PingLunService {
    private PingLunDao PingLunDao = new PingLunDao();

    /**
     * 获取待审核评论
     */
    public List<PingLun> getPendingComments(int currentPage, int pageSize) {
        return PingLunDao.getPendingComments(currentPage, pageSize);
    }

    /**
     * 获取已审核评论
     */
    public List<PingLun> getApprovedComments(int currentPage, int pageSize) {
        return PingLunDao.getApprovedComments(currentPage, pageSize);
    }
    public int addPingLun(PingLun pingLun) {
        return PingLunDao.addPingLun(pingLun);
    }
    /**
     * 获取所有评论
     */
    public List<PingLun> getAllComments(int currentPage, int pageSize) {
        return PingLunDao.getAllComments(currentPage, pageSize);
    }

    /**
     * 审核评论
     */
    public int approveComment(int pingLunId, int status, String adminRemark) {
        return PingLunDao.approveComment(pingLunId, status, adminRemark);
    }

    /**
     * 批量审核评论
     */
    public int batchApproveComments(List<Integer> ids, int status, String adminRemark) {
        return PingLunDao.batchApproveComments(ids, status, adminRemark);
    }

    /**
     * 删除评论
     */
    public int deleteComment(int pingLunId) {
        return PingLunDao.deleteComment(pingLunId);
    }
    public Map<String, Integer> getPingLunStats() {
        Map<String, Integer> stats = new HashMap<>();
        stats.put("total", PingLunDao.getCommentCount(-1)); // 所有评论
        stats.put("pending", PingLunDao.getCommentCount(0)); // 待审核
        stats.put("approved", PingLunDao.getCommentCount(1)); // 已通过
        return stats;
    }
    /**
     * 批量删除评论
     */
    public int batchDeleteComments(List<Integer> ids) {
        return PingLunDao.batchDeleteComments(ids);
    }

    /**
     * 获取评论总数
     * @param status 状态：-1表示所有，0表示待审核，1表示已通过
     */
    public int getCommentCount(int status) {
        return PingLunDao.getCommentCount(status);
    }
}